﻿<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8" />
    <title>JQuery FormUrlEncoded example</title>
    <script src="~/lib/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="~/Scripts/MVC.js"></script>
    <script type="text/javascript">
            $(function () {
                $('#personButton').click(function () {
                    var data = {
                        Name: 'SamplePerson',
                        Address: {
                            Street: 'SampleStreet',
                            City: "SampleCity",
                            State: "SampleState",
                            ZipCode: 11
                        },
                        PastJobs: [
                            {
                                JobTitle: "SampleJob1",
                                EmployerName: 'Employer1',
                                Years: 2
                            },
                            {
                                JobTitle: "SampleJob2",
                                EmployerName: 'Employer2',
                                Years: 4
                            },
                            {
                                JobTitle: "SampleJob3",
                                EmployerName: 'Employer3',
                                Years: 1
                            }
                        ]
                    };

                    $.post('@Url.Action("IsValidPerson", "FormUrlEncoded")', MVC.stringify(data))
                        .done(function (result) {
                            if (result)
                            {
                                $("#validPerson").html("The submitted data belongs to a valid person.");
                            }
                            else
                            {
                                $("#validPerson").html("The submitted data is invalid.");
                            }
                    });
                });
            });
    </script>
</head>
<body>
    <button id="personButton" type="button">Click here to post person data</button><br /><br />
    <p id="validPerson"></p>
</body>
</html>
